Garbage Collection Implemented in Hardware

ABSTRACT

A method of garbage collection in a computing device is provided. The method includes providing a memory module having a memory implemented as at least one hardware circuit. The memory module uses a dual-ported memory configuration. The method includes triggering a garbage collection signal by a sweep engine of the computing device. The sweep engine is in communication with a memory module to reclaim memory. The method includes receiving the garbage collection signal by a root snapshot engine of the computing device. The method includes taking a snapshot of roots from at least one mutator by the root snapshot engine if the garbage collection signal is received. The method includes receiving roots from the root snapshot engine by a trace engine of the computing device. The trace engine is in communication with the memory module to receive data.

CROSS-REFERENCE TO RELATED APPLICATION

This application is a continuation of U.S. patent application Ser. No.13/478,614, filed May 23, 2012, the disclosure of which is incorporatedby reference herein in its entirety.

BACKGROUND

The present invention relates to memory management techniques, and morespecifically, to a garbage collector that is implemented in hardware.

Frequency scaling, which is the technique of ramping processor frequencyto achieve enhance performance, has led to other approaches forenhancing computing performance. One example of another approach forenhancing performance is multiple instruction, multiple data (MIMD)parallelism employing multiple processors. However, MIMD parallelism maybe relatively inefficient, and consumes a relatively high amount ofpower. One alternative to MIMD parallelism is reconfigurable hardwaresuch as, for example, field-programmable gate arrays (FPGA).

One drawback of FPGAs is programming methodology. The most commoncomputer languages for FPGAs are relatively low-level hardwaredescription languages such as, for example, very-high-speed integratedcircuits hardware description language (VHDL) and Verilog. Theselow-level languages use abstractions that are bits, arrays of bits,registers, wires, and other hardware, which make programming FPGAs muchmore complex than conventional central processing units (CPUs). Thus,there is a focus on raising the level of abstraction and programmabilityof FPGAs to that of higher-level software based programming languages.Some examples of recent research are the Kiwi project, whichautomatically translates C# programs into FPGA circuits, or the LiquidMetal project that has developed the Lime language. One fundamentalfeature of high-level languages is automatic memory management, in theform of garbage collection (i.e., attempts to reclaim memory occupied byobjects that are no longer in use by a program). However, whether alow-level language or a higher-level programming language is used, theuse of garbage collection in FPGAs and other types of reconfigurablehardware structures is generally non-existent.

SUMMARY

According to one embodiment of the present invention, a method ofgarbage collection in a computing device is provided. The methodincludes providing a memory module having a memory implemented as atleast one hardware circuit. The memory module uses a dual-ported memoryconfiguration. The method includes triggering a garbage collectionsignal by a sweep engine of the computing device. The sweep engine is incommunication with a memory module to reclaim memory. The methodincludes receiving the garbage collection signal by a root snapshotengine of the computing device. The method includes taking a snapshot ofroots from at least one mutator by the root snapshot engine if thegarbage collection signal is received. The method includes receivingroots from the root snapshot engine by a trace engine of the computingdevice. The trace engine is in communication with the memory module toreceive data.

Additional features and advantages are realized through the techniquesof the present invention. Other embodiments and aspects of the inventionare described in detail herein and are considered a part of the claimedinvention. For a better understanding of the invention with theadvantages and the features, refer to the description and to thedrawings.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

The subject matter which is regarded as the invention is particularlypointed out and distinctly claimed in the claims at the conclusion ofthe specification. The forgoing and other features, and advantages ofthe invention are apparent from the following detailed description takenin conjunction with the accompanying drawings in which:

FIG. 1 is a block diagram of an exemplary field-programmable gate array(FPGA) having a garbage collector according to one aspect of theinvention;

FIG. 2 is a block diagram of a memory module shown in FIG. 1 inaccordance with an embodiment of the present invention;

FIG. 3 is a block diagram of a root snapshot engine shown in FIG. 1 inaccordance with an embodiment of the present invention;

FIG. 4 is a block diagram of a trace engine shown in FIG. 1 inaccordance with an embodiment of the present invention;

FIG. 5 is a block diagram of a sweep engine shown in FIG. 1 inaccordance with an embodiment of the present invention; and

FIG. 6 is a timing diagram of the garbage collector shown in FIG. 1 inaccordance with an embodiment of the present invention.

DETAILED DESCRIPTION

An embodiment of a garbage collector implemented in computer hardware(as opposed to previous hardware-assist techniques) is disclosed. In oneembodiment, a field-programmable gate array (FPGA) and an on-chip memoryare disclosed. Utilizing a concurrent snapshot algorithm, the garbagecollector as disclosed provides single-cycle access to the heap, anddoes not stall a mutator for a single cycle, thus achieving adeterministic mutator utilization (MMU) of about 100%. In variousembodiments, the garbage collector as disclosed does not consume morethan about 2% of the logic resources of a relatively high-end FPGA. Inthe embodiments as disclosed, the garbage collector may include either astop-the-world or a fully concurrent configuration. However, whenimplemented in hardware, real-time collection may achieve a higherthroughput, lower latency, lower memory usage, and energy consumptionwhen compared to the stop-the-world configuration.

With reference now to FIG. 1, a block diagram of an exemplaryfield-programmable gate array (FPGA) 10 is shown having a memory module20. The FPGA 10 includes various programmable gates 12, which may beprogrammed to include one or more modules or engines. In the embodimentas shown, the FPGA 10 includes a trace engine 22, a sweep engine 24, anda root snapshot engine 26. The memory module 20 may store configurationinformation, where a first application interface 30 that is incommunication with the memory module 20, which receives programminginstructions and communicates information to and from a host (notshown). The memory module 20 is also in communication with the traceengine 22 and the sweep engine 24, where the trace engine receives datafrom the memory module 20. A second application interface 32 is incommunication with the root snapshot engine 26. The root snapshot engine26 is in communication with a host (not shown) over the secondapplication interface 32. The host may separately communicate with theroot snapshot engine 26 over the second application interface 32. Thetrace engine 22 and the sweep engine 24 create a garbage collector 34.

Although FIG. 1 illustrates an FPGA, it is understood that any type ofcomputing device having a managed memory implemented as one or morehardware circuits using a hardware description language may be used aswell such as, for example, an application specific integrated circuit(ASIC) having appropriate combinational logic gates or a programmablegate array (PGA). The FPGA 10 may be in communication with a clientapplication that is written in a hardware description language such as,for example, very-high-speed integrated circuits hardware descriptionlanguage (VHDL) and Verilog. The FPGA 10 may also be in communicationwith a client application written in a higher-level software basedprogramming language such as, for example, C, C++, SystemC, Perl,Python, C#, CUDA, Java, OpenCL, or a language that is derived therefrom,where a compiler (not illustrated) converts the higher-level softwarebased programming language into the hardware description language.

In one embodiment, the FPGA 10 is a programmable logic device having 4-or 6-input look-up tables (LUTs) which can be used to implementcombinational logic, and flip-flops (not illustrated) which can be usedto implement sequential logic. Specifically, several LUTs and flip-flopsmay be combined together to form a unit called a slice, which is thestandard unit in which resource consumption is reported for FPGAs. TheFPGA 10 also includes a clock distribution network (not illustrated) forpropagating a globally synchronized clock to allow for the use ofconventional clocked digital logic. In one embodiment, the global clockmay be used to implement an efficient single-cycle atomic root snapshot.The FPGA 10 also contains a relatively large amount of configurablerouting resources for connecting the slices, based on the data flow in ahardware description language program. The routing resources are used bya place-and-route (PAR) tool during hardware synthesis.

The FPGA 10 may employ block random access memory (BRAM), which arespecialized memory structures that are usually available on FPGAs. Forexample, some types of FPGAs may have a BRAM capacity of between 1.5 MBto 8 MB of BRAM. One feature of a BRAM type memory is that BRAM may beorganized in various form factors (i.e., analogous to word sizes on acentral processing unit). One commercially available example of an FPGAis the Virtex®-5 FPGA manufactured by Xilinx Inc., headquartered in SanJose, Calif. One feature of BRAM is that BRAM can be organized invarious form factors (analogous to word sizes on a CPU). On theVirtex®-5, form factors of 1, 2, 4, 9, 18, 36, 72, and so on aresupported. For example, a 36 KB BRAM can also be used as two logicallyseparate 18 KB BRAMs. Moreover, a denser memory structure may be builtby cascading multiple BRAMs horizontally, vertically or, in a hybridconfiguration. Any memory structure which is smaller than 18 KB wouldlead to quantization (i.e., in memory system parlance, this is referredto as fragmentation). The quantization may be considerable, depending onthe logical memory structure in the design.

The BRAM may be used as a true dual-ported (TDP) RAM (shown in FIG. 2 asport A and port B) that provides two fully independent read-write ports.A dual-ported memory has ability to simultaneously read and write todifferent memory cells at different addresses. Moreover, each port onthe BRAM memory supports either read, write, read-before-write, andread-after-write operations. It should be noted that the BRAM may alsobe configured for use as a first in first out (FIFO) queues rather thana random access memory, which is used in the trace engine 22.

The FGPA 10 includes memory structures (e.g., the memory 80 and 82 asillustrated in FIG. 2) that are typically more uniform than conventionalsoftware heaps. Thus, the memory structures in the FPGA 10 are organizedinto one or more miniheaps, in which objects have a fixed size and shapein terms of pointer and data fields. Each miniheap has an interfaceallowing objects to be allocated (and freed when using explicit memorymanagement), and operations allowing individual data fields to be reador written. Miniheaps with one or two pointer fields and one or two datafields are generally employed. The quantization as described above mayimpact efficiency of BRAM utilization. For example, for a miniheap ofsize N=256, pointers are 8 bits wide, so a single 18 KB BRAM configuredas 9 bits wide would be used. However, this wastes 1 bit per entry, butalso wastes 1.75K entries, since only 256 (0.25K) entries are needed.The 1 bit wasted per field is a form of internal fragmentation and the1.75K wasted fields are a form of external fragmentation.

To reduce external fragmentation, multiple fields of the same size maybe implemented with a single BRAM set. However, since BRAMs aredual-ported, supporting more than two fields would result in a loss ofparallelism in terms of field access. Furthermore, since one BRAM portis used for initialization of fields when allocated, this effect comesinto play even with two fields. The opposite approach is also possible:multiple fields can be implemented with a single BRAM set, resulting ina wider data width. In principle this can reduce internal fragmentation.However, in practice, this actually can result in poorer resourceallocation because it reduces flexibility for the synthesis tools.

The memory module 20 receives an allocation request 56, an address tofree port 58, an address to read/write port 60, and a pointer to writeport 62. The allocation request 56 may be a one-bit signal that is usedto implement a malloc operation (e.g., dynamic allocation), and isreceived from a host (not shown) through the first application interface30. The address to free port 58 is in communication with the sweepengine 24, and the address to read/write port 60 and the pointer towrite port 62 are in communication with a host (not shown) through thefirst application interface 30. The memory module 20 sends a pointervalue 70 to the trace engine 22.

A block diagram of the memory module 20 is illustrated in FIG. 2,showing primary data and control fields. Various approaches exist forimplementing the miniheap as described above. Fundamentally, theminiheap represents a time/space (and sometimes power) trade-off betweenthe number of available parallel operations, and the amount of hardwareresources consumed. Regarding the FPGA 10 shown in FIG. 1, a logicalmemory block with a desired data width and number of entries isspecified, and the synthesis tools attempt to allocate the requirednumber of individual block RAMs as efficiently as possible, usingvarious packing strategies. The BRAMs for such a logical memory blockare referred to as a BRAM set. In the various embodiments as described,one BRAM set is used for each field in the object. For example, if thereare two pointers and one data field, then there are three BRAM sets. Thenon-pointer field has a natural width associated with its data type(e.g., 32 bits). However, for a miniheap of size N, the pointer fieldsare [log₂N] bits wide. Thus, because data widths on the FPGA 10 arecustomizable, the precise number of required bits are used. Thus, alarger miniheap will increase in size not only because of the number ofentries, but because the pointer fields become larger. It should benoted that the memory module is the same as in software, where thepointer value 0 is reserved to mean “null”, so a miniheap of size N canreally only store N−1 objects.

For clarity, a single object field memory 80 is illustrated in FIG. 2,which is of pointer type, and is stored in a single BRAM set. A secondset of memory 82 (e.g., a free stack of memory) is also provided tostore a stack of free objects. Both the memories 80 and 82 include adual-port configuration (e.g., having a first port A and a second portB).

The allocation request 56 is sent to a stack top register 84, which isused to hold the value of a stack top of the second set of memory 82.Assuming the value of the stack top register 84 is a non-zero value, thestack top register 84 is decremented and sent to port B of the memory82, in read mode. A resulting pointer 86 from the memory 82 is also theaddress allocated port 72. The resulting pointer 86 is also sent to portB of the memory 80, in write mode. A resulting write value of theresulting pointer 86 is hard wired to null (e.g., ‘000’). To free anobject a pointer (e.g., the address to free signal 58) is presented tothe memory module 20, and the stack top register 84 is used as theaddress for the memory 82 on port B, in write mode, with the data valueof the address to free signal 58. The stack top register 84 isincremented, which causes a pointer 90 to the freed object to be pushedonto the freed stack of memory 82.

In order to read or write to a field in the pointer memory 80, theaddress to read write signal 60 is presented, and if writing the pointerto write signal 62 is presented. This utilizes port A of the memory 80in either read or write mode, resulting in the pointer value 70 in thewrite mode. Thus, as shown in FIG. 2, the memory module 20 can allow aread or write to proceed in parallel, which is allowed by theduel-ported memories 80 and 82.

Turing back to FIG. 1, the root snapshot engine 26 may use a Yuasa-stylesnapshot-at-the-beginning algorithm (i.e., an algorithm that uses thesnapshot-at-the-beginning strategy to preserve every reference at thebeginning of garbage collection, and new objects allocated duringgarbage collection are also preserved). A root snapshot may be obtainedvirtually without stopping an application while the snapshot is taken.The root snapshot engine 26 takes two types of roots from one or moremutators, those in the registers and those in the stack.

Referring now to FIG. 3, the root snapshot engine 26 is illustrated witha single mutator stack 90 and a single mutator register 92. The snapshotis controlled by a garbage collector (GC) signal sent from the sweepengine 24 (shown in FIG. 1). The GC signal goes high for one clock cycleat the beginning of collection. The snapshot of the roots is defined asthe state of memory at the beginning of a next cycle after the GC signalgoes high. A snapshot of the mutator register 92 is obtained by using ashadow register 100. In the cycle after the GC signal goes high, thevalue of the mutator register 92 is copied into the shadow register 100.This can happen even if the mutator register 92 is also written by themutator in the same cycle, since the new value will not be latched untilthe end of the cycle.

The stack snapshot is obtained by having another register in addition toa stack top register 102, which is referred to as a scan pointerregister 104. In the same cycle that the GC signal goes high, the valueof a stack top register pointer 106 minus one is written into the scanpointer register 104 (because the stack top points to the entry abovethe actual top value). Beginning in the following cycle, the scanpointer register 104 is used as the source address to port B of themutator stack 90, and a pointer 110 is read out, going through amultiplexer 112 (MUX) and emerging on a root to add port 114 from thesnapshot module. The scan pointer register 104 is also decremented inpreparation for the following cycle. It should be noted that the mutatorcan continue to use the mutator stack 90 via port A of the BRAM set,while the snapshot uses port B of the mutator stack 90. Moreover,because the mutator cannot pop values off the stack faster than acollector can read the values, the property is preserved that thesnapshot contains exactly the roots that existed in the cycle followingthe GC signal.

One feature omitted from FIG. 3 is that a state machine (not shown) isrequired to sequence the values from the mutator stack 90 and the shadowregister 100 through the multiplexer 112 to the root to add port 114. Itshould be noted that the values from the mutator stack 90 are processedfirst, because the stack snapshot technique relies on staying ahead ofthe mutator without any explicit synchronization. If multiple stacks areprovided, then a shadow stack will be provided to hold values as theywere read out before the mutator could overwrite the hold values, whichcould then be sequenced onto the root to add port 114. As will bediscussed below, the GC signal is only triggered by an allocationrequest by the mutator that causes free space to drop below a threshold.Therefore, the generation of root snapshot logic only needs to considerthe hardware states in which this might occur. Any register or stack notlive in those states can be safely ignored.

Turning back to FIG. 1, the trace engine 22 includes a single pointermemory (shown in FIG. 4 as reference number 120). The trace engine 22provides the same mutator interference as the malloc/free style memorymanagement approach of the memory module 20. In particular, referring toboth FIGS. 1 and 4, the trace engine 22 also includes an address to readport 130, a pointer to write port 132, and a pointer value port 70,except that instead of the address to free port 58 (shown in FIG. 2), anaddress to clear port 136 is provided. Also, the root to add port 114from the root snapshot engine 26 is provided.

Continuing to refer to FIG. 4, during execution, there are three sourcesof pointers for the trace engine 22 to trace: externally added rootsfrom the snapshot (e.g., the root to add port 114 from the snapshotengine 26), internally traced roots from the pointer memory 120, andover-written pointers from the pointer memory 120 (which is capturedwith a Yuasa-style barrier to maintain the snapshot property). Thedifferent pointer sources flow through a multiplexer 140, and on eachcycle a pointer 142 (e.g., pointer to trace) can be presented to a markmap 146 (which is a dual-ported memory), and contains one bit for eachof the N memory locations. Using the BRAM read-before-write mode, an oldmark value is read, and then the mark value is unconditionally set to 1.If the old mark value is 0, this pointer has not yet been traversed, sothe negation of the old mark value (indicated by the bubble 150) is usedto control whether a pointer 152 is added to a mark queue 154 (note thatthis means that all values in the mark queue 154 have been filtered, soat most N−1 values can flow through the queue). The mark queue 154 is aBRAM used in FIFO (rather than random access) mode.

Pointers from the mark queue 154 are presented as a read address on portB of the pointer memory 120, and if non-null values are fed to amultiplexer 155 back to the marking step. The write barrier isimplemented by using port A of the pointer memory 120 BRAM inread-before-write mode. When the mutator writes a pointer, the old valueis read out first and placed into a barrier register 156. This issubsequently fed through the multiplexer 140 and marked. Given the threeBRAMs involved in the marking process, processing one pointer requires 3cycles. However, the marking engine is implemented as a 3-stagepipeline, and is able to sustain a throughput of one pointer per cycle.

For objects with two pointers, two trace engines may be provided andpaired together to maximize resource usage (not shown). Since each traceengine only uses one port of the mark map, both engines can markconcurrently. Furthermore, the two mark queues are multiplexed togetherand the next item to mark is always taken from the less full queue. Thisallows the queues to be of size N/2. On each cycle, one pointer isremoved from the queue, and the two pointers in the object retrieved areexamined and potentially marked and enqueued. The final optimization isthat since there are now two write barrier registers and two markqueues, the write barrier values are not processed until there are twoof them. This means that the mark engines can make progress every othercycle even if the application is performing one write per cycle.

The termination protocol for marking is relatively simple: once the lastitem from the mark queues 154 is popped (both mark queues become empty),it takes 2 or 3 cycles for the trace engine 22 to finish the currentpipeline. If the two pointers returned by the heap are null, then themark process is terminated in the 2nd cycle as there is no need to readthe mark bits in this case. Otherwise the mark bit for the non-nullpointers are read to ensure that both pointers are marked, in which casethe mark phase is terminated in the third cycle.

Write barrier values arriving after the first cycle of termination canbe ignored, since by the snapshot property would either have to be newlyallocated or else discovered by tracing the heap. However, note thatsome data structures (e.g., linked lists) will cause a pathologicalbehavior, in which a pointer is marked, removed from the queue, whichwill appear empty, and then 2 cycles later the next pointer from thelinked list will be enqueued. So while the pipeline can sustain markingone object per cycle, pipeline bubbles will occur which reduce thatthroughput.

Turning back to FIG. 1, the sweep engine 24 is provided, where sweepingwill begin during the next machine cycle after the tracing in the traceengine 22 has been completed. During sweeping, memory is reclaimed. Amark signal 160 is sent from the trace engine 22 to the sweep engine 24to indicate that the tracing has been completed. Referring now to FIG.5, the sweep engine 24 receives the allocation request 56 from themutator. The sweep engine 24 handles the allocation request 56 andmaintains a stack of pointers to a free memory that is a free stack 164.The sweep engine 24 also includes the mark map 146 of the trace engine22 (shown in FIG. 4).

When the allocation request 56 is received, a stack top register 166 isused to remove a pointer to a free object from the free stack 164,thereby decrementing a stack pointer 168. If the stack pointer 168 fallsbelow a specified level then the GC signal is triggered by raising theGC signal. Referring to both FIGS. 1 and 4-5, the GC signal is sent fromthe stack top 166 of the sweep engine 24 to the root snapshot engine 26.In one embodiment, the specified level of the stack pointer 168 is about25%, however it is to be understood that the specified level may includeother values as well. Specifically, the specified level may be based onone or more application and resource parameters such as, for example,allocation rates, mutation rates, live data amount, and memory resource.

The address popped from the free stack 164 is returned to the mutator onan address allocated port 169. The address is also used to set anobject's entry in a used map 170 to the value 01, which means “freshlyallocated”. A value of 00 means “free”, in which case the object is onthe free stack 164.

Sweeping is a simple linear scan. A sweep pointer 172 initialized to 1(since slot 0 is reserved for null), and on every cycle (except whenpre-empted by allocation) the sweep pointer is presented to both themark map 146 and the used map 170. If an object is marked, the used map170 entry is set to ‘10’. If an object is not marked and the used map170 entry is ‘10’ (which is indicated by an and gate 180 in FIG. 5) thenthe used map entry is set to 00. The resulting signal is also used tocontrol whether the current sweep pointer 172 address is going to befreed. If so, the sweep pointer 172 is pushed onto the free stack 164and also output on the address to clear port 136, which is connected tothe mark engine (e.g., the mark map 146) so that the data values beingfreed are zeroed out.

It should be noted that since clearing only occurs during sweeping,there is no contention for port B of the pointer memory 120 in the traceengine 22 (FIG. 4) between clearing and marking. Furthermore, it shouldalso be noted that an allocation request and a free request may happenin the same cycle (e.g., the stack top 84 as shown in FIG. 2 is accessedusing read-before-write mode and returned as the address allocatedsignal 72, and then the newly freed object is pushed back).

When an object is allocated, the object is not marked. Thus, the garbagecollector 36 (shown in FIG. 1) does not allocate black, which means thatthe tracing engine 22 may encounter newly allocated objects in themarking pipeline (via newly installed pointers in the heap), albeit atmost once since the pointer will then be marked. This also affectsworst-case execution time (WCET) analysis.

Referring generally to FIGS. 1-5, the configuration of the garbagecollector 36 thus allows for mutation and collection to occurunconditionally, in a single cycle. Thus, the minimum mutatorutilization (MMU) is about 100%, unless insufficient resources arededicated to the heap. Turning now to FIG. 6, a timing chart of thegarbage collector 36 is illustrated. As shown in FIG. 6, garbagecollection is triggered or initiated by the GC signal sent from thesweep engine 24 (shown in FIG. 1). Referring now to FIGS. 1 and 6, theGC signal is triggered if the pointer 168 (of the sweep engine 24 shownin FIG. 5) falls below the specified level (e.g., in one embodiment thespecified level is 25%). The GC signal goes high for one clock cycle atthe beginning of garbage collection. The root snapshot module 26receives the GC signal and takes a snapshot of the roots from themutator during the root snapshot phase.

The root snapshot engine 26 sends the root to add port 114 (e.g., thesnapshot of the mutator) to the trace engine 22. Thus initiates a markphase in the trace engine 22. The trace engine 22 is implemented as a3-stage pipeline, having a throughput of one pointer per clock cycle.The mark signal 160 is sent from the trace engine 22 to the sweep engine24 during a mark done phase to indicate that the tracing has beencompleted. The sweep phase then begins, where memory is reclaimed (e.g.,the address to free port 58 sent back to the memory module 20). The GSsignal triggered by the sweep engine 24 each time the pointer 168 (ofthe sweep engine 24 shown in FIG. 5) falls below the specified level.

Unlike software-based garbage collectors, the garbage collector asdescribed in FIGS. 1-6 is fully deterministic, as it is possible toanalyze the worst case behavior down to a (machine) cycle. For example,given R is the maximum number of roots and N is the size of the heap,then the worst-case time (in cycles) for garbage collection is:

T=T _(R) +T _(M) +T _(W) +T _(X) +T _(S) +T _(A)

where T_(R) is the time to snapshot the roots, T_(M) is the time (incycles) to mark, T_(S) is the time to sweep, and T_(W) is the time lostto write barriers during marking, T_(X) is the time lost to blackeningnewly allocated objects during marking, and T_(A) is time lost toallocations during sweeping. In the worst case, without any knowledge ofthe application, T_(R)=R+2, T_(M)=3N+3, T_(W)=0 T_(X)=0, and T_(S)=N.

The reasoning for these quantities will now be explained. During thesnapshot phase, one root into the mark queue every cycle may be placed,plus one cycle to start and finish the phase, accounting for R+2. Duringmarking (e.g., performed by the trace engine 22), there could be Nobjects in the heap, configured as a linked list which causes the markpipeline to stall for two cycles on each object, plus 3 cycles toterminate. Sweeping (performed by the sweep engine 24) is unaffected byapplication characteristics, and always takes N cycles. Preemption ofthe collector by mutator write barriers (T_(W)) does not factor into theworst-case analysis because the write barrier work is overlapped withthe collector stalls. Extra mark operations to blacken newly allocatedobjects (T_(X)) also simply fill stall cycles.

The garbage collector as described in the embodiments shown in FIGS. 1-6allows an allocation operation in every cycle, but allocation pre-emptsthe sweep phase, meaning that such an allocation rate can only besustained in relatively short bursts. The largest sustainable allocationrate is 0.5—otherwise the heap would be exhausted before sweepingcompleted. Thus, T_(A)=N and T_(worst)=R+5N+5.

In one approach, real-time analysis may be performed where μ is theaverage number of mutations per cycle (μ≦1), α is the average number ofallocations per cycle (α<0.5), and m is the maximum number of live dataobjects in the heap at any one time (m<N). The following equations areprovided:

$\begin{matrix}{{T_{M} = {{3m} + 3}},} \\{{T_{S} = N},} \\{{T_{W} = {\frac{\mu}{2 - \mu}m}},} \\{T_{A} = {\frac{\alpha}{1 - \alpha}N}}\end{matrix}$

It should be noted that both α and μ can only be averaged over a timewindow guaranteed to be less than or equal to the phases which α and μinfluence, and m is a safe window size. One inaccuracy may be due topipeline stalls during marking, for which worst and average casebehavior can be very different. Thus, B is the number of pipeline stalls(0≦B≦2m), so T_(M)=m+B+3. For a linked list, B=2m; for three linkedlists each with its own root, B=0. For a heap considered as a forestwithout back-edges, B is bounded by the number of levels of width 1 plusthe number of levels of width 2 (when the width is 3 or greater, thereis enough parallelism to keep the 3-stage pipeline full and avoidstalls).

Using these application-specific estimates, the WCET of collection isexpressed as:

$T_{\max} = {R + {( \frac{1}{1 - \alpha} )( {{\frac{2}{2 - \mu}m} + N} )} + B + 5}$

Once the worst-case execution time for collection is known, the minimumheap size in which the collector can run with real-time behavior (zerostalls) is determined, where m objects are available for the live data.While a collection taking time T_(max) takes place, another αT_(max)objects can be allocated (the so-called floating garbage). However,there may be αT_(max) floating garbage when a collection starts, andthen another αTmax objects will be allocated during that collection.Thus the minimum heap size is:

N _(min) =m+2αT _(max)

If the non-size-dependent portion of T_(max) from the previous equationis denoted as:

${K = {R + {( \frac{1}{1 - \alpha} )( {\frac{2}{2 - \mu}m} )} + B + 5}},$

and the following is solved:

$\begin{matrix}{N_{\min} = {m + {2\; \alpha \; T_{\max}}}} \\{N_{\min} = {m + {2\; {\alpha ( {\frac{N_{\min}}{1 - \alpha} + K} )}}}} \\{N_{\min} = {( {m + {2\; \alpha \; K}} )( \frac{1 - \alpha}{1 - {3\alpha}} )}}\end{matrix}$

A micro-benchmark was performed with three different types of memorymanagement implementations, an explicit (e.g., malloc/free) memorymanagement, real-time collection, and a stop-the-world collector. Thecomparison was performed using the Virtex®-5 FPGA. It should be notedthat when implemented in hardware, the real-time collector is faster,has lower latency, can run more effectively in less space, and consumesless energy when compared to a stop-the-world collector.

As will be appreciated by one skilled in the art, aspects of the presentinvention may be embodied as a system, method or computer programproduct. Accordingly, aspects of the present invention may take the formof an entirely hardware embodiment, an entirely software embodiment(including firmware, resident software, micro-code, etc.) or anembodiment combining software and hardware aspects that may allgenerally be referred to herein as a “circuit,” “module” or “system.”Furthermore, aspects of the present invention may take the form of acomputer program product embodied in one or more computer readablemedium(s) having computer readable program code embodied thereon.

The terminology used herein is for the purpose of describing particularembodiments only and is not intended to be limiting of the invention. Asused herein, the singular forms “a”, “an” and “the” are intended toinclude the plural forms as well, unless the context clearly indicatesotherwise. It will be further understood that the terms “comprises”and/or “comprising,” when used in this specification, specify thepresence of stated features, integers, steps, operations, elements,and/or components, but do not preclude the presence or addition of onemore other features, integers, steps, operations, element components,and/or groups thereof.

The corresponding structures, materials, acts, and equivalents of allmeans or step plus function elements in the claims below are intended toinclude any structure, material, or act for performing the function incombination with other claimed elements as specifically claimed. Thedescription of the present invention has been presented for purposes ofillustration and description, but is not intended to be exhaustive orlimited to the invention in the form disclosed. Many modifications andvariations will be apparent to those of ordinary skill in the artwithout departing from the scope and spirit of the invention. Theembodiment was chosen and described in order to best explain theprinciples of the invention and the practical application, and to enableothers of ordinary skill in the art to understand the invention forvarious embodiments with various modifications as are suited to theparticular use contemplated

The flow diagrams depicted herein are just one example. There may bemany variations to this diagram or the steps (or operations) describedtherein without departing from the spirit of the invention. Forinstance, the steps may be performed in a differing order or steps maybe added, deleted or modified. All of these variations are considered apart of the claimed invention.

While the preferred embodiment to the invention had been described, itwill be understood that those skilled in the art, both now and in thefuture, may make various improvements and enhancements which fall withinthe scope of the claims which follow. These claims should be construedto maintain the proper protection for the invention first described.

What is claimed is:
 1. A method of garbage collection in a computingdevice, comprising: providing a memory module having a memoryimplemented as at least one hardware circuit, the memory module using adual-ported memory configuration; triggering a garbage collection signalby a sweep engine of the computing device, the sweep engine incommunication with a memory module to reclaim memory; receiving thegarbage collection signal by a root snapshot engine of the computingdevice; taking a snapshot of roots from at least one mutator by the rootsnapshot engine if the garbage collection signal is received; andreceiving roots from the root snapshot engine by a trace engine of thecomputing device, the trace engine in communication with the memorymodule to receive data.
 2. The method of claim 1, comprising triggeringthe garbage collection signal if a stack pointer of the sweep enginefalls below a specified level.
 3. The method of claim 2, comprisingreceiving an allocation request by a stack top register of the sweepengine, wherein the stack top register is used to remove a pointer to afree object from a free stack that decrements the stack pointer.
 4. Themethod of claim 2, wherein the specified level is based on at least oneof an allocation rate, a mutation rate, a live data amount, and a memoryresource.
 5. The method of claim 1, comprising providing an address tofree port to the sweep engine, wherein the memory module is incommunication with the sweep engine by the address to free port.
 6. Themethod of claim 1, comprising providing a shadow register and a mutatorregister of the root snapshot engine.
 7. The method of claim 6,comprising having the garbage collection signal going high for one clockcycle.
 8. The method of claim 7, comprising copying a value of themutator register into the shadow register after the garbage collectionsignal goes high.
 9. The method of claim 8, comprising sending theshadow register and a mutator through a multiplexer of the root snapshotengine, wherein a pointer that is read from the mutator stack emergesfrom the multiplexer as the snapshot of roots from the at least onemutator.
 10. The method of claim 1, comprising sending a pointer valuefrom the memory module to the trace engine.
 11. The method of claim 1,comprising allowing a read and a write operation to proceed in parallelby the dual-ported memory configuration of the memory module.
 12. Themethod of claim 1, comprising communicating with the computing devicewith a client application that is written in a hardware descriptionlanguage.
 13. The method of claim 12, wherein the hardware descriptionlanguage is one of a very-high-speed integrated circuits hardwaredescription language (VHDL) and Verilog.
 14. The method of claim 1,comprising communicating with the computing device by a clientapplication that is written in a software based programming language.15. The method of claim 14, wherein the software based programminglanguage is one of C, C++, SystemC, Perl, Python, C#, CUDA, OpenCL,Java, and a language that is derived therefrom, and wherein a compilerconverts the software based programming language into a hardwaredescription language.